package com.jgy.controller;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.jgy.annotation.SetLogValue;
import com.jgy.handler.LightException;
import com.jgy.service.FileService;
import com.jgy.utils.CommonConstants;
import com.jgy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 姜光远
 * @date 2023/4/26 10:39
 */
@RestController
@RequestMapping("/file")
public class FileAliyunOssController {

    @Autowired
    private FileService fileService;

    @SetLogValue(modular = "文件上传",type = CommonConstants.SELECT, describe = "oss文件上传")
    @PostMapping("uploadFile")
    @DS("master")
    public R uploadFile(@RequestParam("file") MultipartFile file) {
        //1获取文件
        //2调用接口上传文件，获取Url
        String url = null;
        try {
            url = fileService.uploadFileOss(file);
        } catch (Exception e) {
            e.printStackTrace();
            throw new LightException(1,"获取失败");
        }
        return R.ok(url);

    }
}
